﻿using System;
using System.Collections.Generic;
using System.Linq;
using DataAccessLibrary.DAL;
using entities;

namespace BusinessLogicLibrary
{
    public class CheckInModule
    {
        private readonly CheckinDAO _checkinDAO = new CheckinDAO();
        private readonly EmployeeDAO _employeeDAO = new EmployeeDAO();

        public List<CheckIn> GetCheckInsByBookingId(int bookingId)
        {
            return _checkinDAO.SelectCheckInsByBookingId(bookingId);
        }

        public bool RemoveCheckIn(int checInId)
        {
            return _checkinDAO.DeleteCheckIn(checInId);
        }

        public CheckIn GetCheckIn(int checkinId)
        {
            return _checkinDAO.SelectCheckIn(checkinId);
        }

        public List<CheckIn> GetCheckInsByCustomerId(int customerId)
        {
            return _checkinDAO.SelectCheckInsByCustomerId(customerId);
        }

        public List<CheckIn> CheckInsIncome()
        {
            return _checkinDAO.SelectCheckInsIncome();
        }

        public List<vSupplyOrder> GetSupplyOrders(int checkinId)
        {
            return _checkinDAO.SelectSupplyOrders(checkinId);
        }

        public bool LockCheckin(List<int> checkinIds)
        {
            return _checkinDAO.LockCheckin(checkinIds);
        }

        public bool AcceptCheckins(int checkinId, string employeeAccount, string employeePassword, string guestInfo)
        {
            Employee employee = _employeeDAO.SelectEmployee(employeeAccount, employeePassword);
            if (!Roles.InternalRoles.Any(s => employee.EmployeePosition == s))
                throw new Exception("Invalid employee");
            return _checkinDAO.AcceptCheckIn(checkinId, employee.EmployeeID, guestInfo);
        }

        public bool ModifyCheckin(int checkinId, string guestInfo)
        {
            var checkin = new CheckIn {CheckInID = checkinId, GuestInfo = guestInfo};
            return _checkinDAO.UpdateCheckIn(checkin);
        }
    }
}